from src.bean.config_column_enum import ConfigColumnEnum
from src.bean.model_database_enum import ModelDatabaseEnum
from src.bean.x_typing import PRE_HANDLE_TYPE
from src.model.model_common_util import get_model, common_predict
from src.model.v1.v1_train import get_df_by_path
from src.model.v2.v2_increasing import v2_increasing_train_entrance
from src.model.v2.v2_pre_handle import v2_file_pre_handle
from src.util.common_util import printx
from src.util.config_manager import ConfigManager
from src.util.file_selector_util import select_multi_file


def v2_predict_file_entrance(config: ConfigManager) -> None:
    old_model = get_model(config)
    if old_model is None:
        return
    file_path_list = select_multi_file(config.get_config(ConfigColumnEnum.use_terminal.value),
                                       title="[文件预测]请输入文件路径(英文逗号隔开):")
    if len(file_path_list) == 0:
        printx("请重新选择文件")
        return
    df, files = get_df_by_path(file_path_list)
    df, cluster, df2 = v2_file_pre_handle(df, model_id=old_model[ModelDatabaseEnum.id.value],
                                          handle_type=PRE_HANDLE_TYPE.predict)
    # 预测的增量只记录预测有问题的数据的聚类方式
    common_predict(config, df, df2, old_model, file_path_list, increasing_method=v2_increasing_train_entrance)
